package com.example.demo.service;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import com.example.demo.di.SpringExtension;
import com.example.demo.model.Greeting;
import com.example.demo.model.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2018/2/7.
 */
@Service
public class BusinessService {

//    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ActorSystem actorSystem;

    @Autowired
    private SpringExtension springExtension;

    public void perform(Message message) {
        ActorRef printerActor = actorSystem.actorOf(springExtension.props("printerActor"), "printer-actor-" + String.valueOf(message.getId()));
        printerActor.tell(new Greeting(message.getPayload() + String.valueOf(message.getId())), ActorRef.noSender());
    }
}
